<?php

namespace App\Console\Commands;

use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Rap2hpoutre\FastExcel\FastExcel;

class RetrybindVoucher extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'RetrybindVoucher';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
//        $cont = file_get_contents('storage/bjxfq.csv');
        $collection = (new FastExcel())->configureCsv(';', '#', 'gbk')->import('storage/bjxfq.csv');

        $client = new Client(['headers' => ['Authorization' => 'Bearer 0000b5897262607bf0d456d850c1c27fbba133e7']]);
        foreach ($collection as $item) {
            $item = current($item);
            $item = trim($item,'"');
            $item = str_ireplace('""', '"', $item);
            $item = json_decode($item, true);

            $res = $client->request('POST', 'https://openapi.lecoosys.com/openapi/v1/Bjsxfq/bindCoupon', ['form_params' => $item]);
            dump($res->getBody()->getContents());
        }
        return 0;
    }
}
